package org.webscale.gae;
import java.util.Collection;
import java.util.logging.Logger;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;

import com.google.appengine.api.datastore.Key;

public abstract class AbstractDao implements GenericDao{

	private static final Logger log = Logger.getLogger(AbstractDao.class
			.getName());
	 
	 protected PersistenceManager getPM(){
		 return TXManager.instance().getPM();
	 }
	 
	 
	 public void makePersistant(Object obj) {
		 PersistenceManager pm = getPM();
		 pm.makePersistent(obj);
	 }

	 	 
	 public Object getObjectByKey(Key key, Class x) {
			return getPM().getObjectById(x, key);
		
		}
	 
	 public void deleteTable(Class clazz){
		 Query query = getPM().newQuery(clazz);
		// query.setRange(0,300);
		 Collection result = (Collection) query.execute();
		 getPM().deletePersistentAll(result);
	 }
	 
	 
}
